<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-26 15:16:08
 * @LastEditTime: 2020-08-19 09:23:23
 * @LastEditors: Please set LastEditors
 -->
<template>
<div class="container">
<van-nav-bar title="拖拽组件" :border="false" fixed left-arrow @click-left='$router.push("/")'/>
    <div class="row">
      <vuedraggable
        class="list-group"
        tag="ul"
        v-model="list"
        v-bind="dragOptions"
        @start="isDragging = true"
        @end="isDragging = false"
      >
        <transition-group type="transition" name="flip-list">
          <li
            class="list-group-item"
            v-for="element in list"
            :key="element.order"
          >
            {{ element.name }}
          </li>
        </transition-group>
      </vuedraggable>
      <div @click.stop="sort" style="display:inline-block">
          <van-button type="primary">还原</van-button>
      </div>
     
      </div>
  </div>
</template>

<script>

const message = [
  "王花花",
  "李栓蛋",
  "张全蛋",
  "赵可爽",
 
];

export default {
  name: "Drag",
  display: "Transition",
  order: 6,
  data() {
    return {
      list: message.map((name, index) => {
        return { name, order: index + 1 };
      })
    };
  },
  methods: {
    sort() {
      this.list = this.list.sort((a, b) => a.order - b.order);
    }
  },
  computed: {
    dragOptions() {
      return {
        animation: 0,
        group: "description",
        disabled: false,
        ghostClass: "ghost"
      };
    }
  }
};
</script>

<style scoped>
.row{
  display: block;
  box-sizing: border-box;
  padding:10px;
}


.flip-list-move {
  transition: transform 0.5s;
}

.no-move {
  transition: transform 0s;
}

.ghost {
  opacity: 0.5;
  background: #c8ebfb;
}

.list-group {
  min-height: 20px;
  display: flex;
  justify-content: space-around;
  flex-direction: column;
  align-items: center;
  list-style: none;
}

.list-group-item {
  cursor: move;
  border:2px solid #ccc;
  padding:20px;
  margin:5px auto;
  border-radius: 5px;
  font-size: 24px;
}

.list-group-item i {
  cursor: pointer;
}
</style>
